/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c) 2002, GeoVISTA Center
 * Licensed under Simplified BSD License
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * @original author: jin Chen 
 * @author: jin Chen 
 * @date: Nov 19, 2008$
 * @version: 1.0
 */
package edu.psu.geovista.app.vit.pub.components.ptnbskt;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import epoviz.trex.common.swing.frame.workspace.xml.XStreamSerializer;
import epoviz.trex.common.xml.xstream.XSerializable;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;


public class Persistool implements XSerializable {
        transient MyBasket bsk;
        transient String root;// 
        private Map<Object,Set> dataGroups; // 
        private  Map<Object, Properties> dataAttributes;// 

    public void save() throws IOException {
        Map<Object, Set> selmap = bsk.getSelections();
        this.setDataGroups(selmap);
        Map<Object, Properties> attmpa = bsk.getAttributes();
        this.setDataAttributes(attmpa);
        XStreamSerializer persist=new XStreamSerializer();
        persist.setObject(this);
        persist.save(this);
    }

    public Object load(File file) throws FileNotFoundException {
        XStreamSerializer persist=new XStreamSerializer();
        persist.setObject(this);
        persist.setStringAsAttribute(true);
        Persistool pm = new Persistool();
        pm= (Persistool) persist.load(pm, file);
        Map<Object, Set> dg = pm.getDataGroups();
        Map<Object, Properties> dp = pm.getDataAttributes();
        bsk.setSelections(dg, dp);
        return dg;  //To change body of implemented methods use File | Settings | File Templates.

    }

    public Class[] getAliasClasses() {
        return new Class[0];  //To change body of implemented methods use File | Settings | File Templates.
    }

    public Converter[] getConvertor() {
        return new Converter[0];  //To change body of implemented methods use File | Settings | File Templates.
    }

    public SingleValueConverter[] getSingleValueConvertor() {
        return new SingleValueConverter[0];  //To change body of implemented methods use File | Settings | File Templates.
    }

    public String getPersistentFileName() {
         return this.getRoot() +File.separator+ "selections.xml";
    }
       public Map<Object, Set> getDataGroups() {
        return dataGroups;
    }

    public void setDataGroups(Map<Object, Set> dataGroups) {
        this.dataGroups = dataGroups;
    }

    public Map<Object, Properties> getDataAttributes() {
        return dataAttributes;
    }

    public void setDataAttributes(Map<Object, Properties> dataAttributes) {
        this.dataAttributes = dataAttributes;
    }

    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        this.root = root;
    }

    public MyBasket getBsk() {
        return bsk;
    }

    public void setBsk(MyBasket bsk) {
        this.bsk = bsk;
    }
}
